package com.example.lenovo.demo.presenter.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.ListView;
import android.widget.TextView;

import com.example.lenovo.demo.R;
import com.example.lenovo.demo.model.databean.CityBean;
import com.example.lenovo.demo.model.databean.ModelDaysBean;
import com.example.lenovo.demo.view.utils.GvHeightUtil;

import java.util.List;
import java.util.Map;

/**
 * Created by Lenovo on 2017/1/12.
 */

public class MapFragment_ExpandableLvAdapter extends BaseExpandableListAdapter {
    private Map<String,List<ModelDaysBean.DataBean.DaysBean.PointsBean>> data;
    private Context context;
    private String[] keys;


    public MapFragment_ExpandableLvAdapter(String[] keys,Map<String,List<ModelDaysBean.DataBean.DaysBean.PointsBean>> data, Context context) {
        this.data = data;
        this.context = context;
        this.keys=keys;
    }
    //父项的数量
    @Override
    public int getGroupCount() {
        return data.size();
    }
    //子项的数量
    @Override
    public int getChildrenCount(int i) {
        return data.get(keys[i]).size();
    }
    //获得所有父项
    @Override
    public Object getGroup(int i) {
        return data.get(keys[i]);
    }
    //获得所有子项
    @Override
    public Object getChild(int i, int i1) {
        return data.get(keys[i]).get(i1);
    }
    //获得父项的id
    @Override
    public long getGroupId(int i) {
        return i;
    }
    //获得子项的id
    @Override
    public long getChildId(int i, int i1) {
        return i1;
    }

    @Override
    public boolean hasStableIds() {
        return false;
    }

    @Override
    public View getGroupView(int i, boolean b, View view, ViewGroup viewGroup) {
        TextView textView;
        if(view==null){
            LayoutInflater inflater=LayoutInflater.from(context);
            view=inflater.inflate(R.layout.mapactivity_rv_item,viewGroup,false);
            textView= (TextView) view.findViewById(R.id.mapactivity_rv_item);
            view.setTag(textView);
        }else {
            textView= (TextView) view.getTag();
        }
        textView.setText(keys[i]);
        return view;
    }

    @Override
    public View getChildView(int i, int i1, boolean b, View view, ViewGroup viewGroup) {
        TextView textView;
        if(view==null){
            view=LayoutInflater.from(context).inflate(R.layout.mapactivity_rv_include,viewGroup,false);
            textView= (TextView) view.findViewById(R.id.mapactivity_include_rv);
            view.setTag(textView);
        }else {
            textView= (TextView) view.getTag();
        }
        textView.setText(data.get(keys[i]).get(i1).getInspiration_activity().getTopic());
        return view;
    }
    //子项是否可选中，设置子项监听时为true
    @Override
    public boolean isChildSelectable(int i, int i1) {
        return true;
    }
}
